param(
	[Parameter(Mandatory=$True)]    
	[string]$reg_list_file,        											# the file that stores the registries
	[Parameter(Mandatory=$True)]   											
	[string]$domain,               											# the domain to be put in csv file
	[Parameter(Mandatory=$True)]   											
	[string]$fid,                  											# the fid to be used to check HKCU:\...
	[Parameter(Mandatory=$false)]    
	[string]$remote_folder="\\sd-1423-49dd\test\VDIConfigInfo\temp\ie\"     # the remote master folder to be copied the csv file to
)
Function Traverse-RegistryKey( $regkey ){
	If( $regkey.Substring($regkey.Length-1) -eq "\"){$regkey=$regkey.Substring(0,$regkey.Length-1)}
	$regkey=$regkey `
		-replace("^HK(EY_)*CU(RRENT_USER)*:*","HKU:\$sid") `
		-replace("^HK(EY_)*L(OCAL_)*M(ACHINE)*:*","HKLM:") `
		-replace("^HKEY_USERS","HKU:") `
		-replace("^HKEY_LOCAL_MACHINE","HKLM:")
	If($regkey -inotmatch "International\\Scripts|SearchScopes|Suggested Sites|(Favorite|About|Typed)URLs(Time)*|UrlTemplate|(Next)??Update.*Date(Time)??|C:\\Users\\$fid|Cache\\" ){
		Foreach( $pro in (get-item $regkey).Property){
			If( $pro -inotmatch "^Scripts|^vbs|C:\\Users\\$fid|Cache\\" ){
				$value=[String]::join(",",(Get-ItemPropertyValue $regkey $pro))
				$csv_regkey=$regkey.replace("HKU:\$sid","HKCU:").replace($sid,'$sid')
				$Script:ie_settings+="`"IE`",`"$csv_regkey\$pro`",`"$value`""
			}
		}
		Foreach( $key in (dir -LiteralPath $regkey).name){
			Traverse-RegistryKey $key
		}
	}
}
$this_path = Split-Path -Parent ($MyInvocation.MyCommand.Definition)
$this_machine=$env:computername
New-PSDrive -Name HKU -PSProvider Registry -Root Registry::HKEY_USERS 1>$null 2>&1
$sid=(New-Object System.Security.Principal.NTAccount("$domain\$fid")).Translate([System.Security.Principal.SecurityIdentifier]).value
$Script:ie_settings=@()
$ie_settings+="`"Category`",`"Setting`",`"$this_machine/$fid/$domain`""
Foreach( $key in (cat "$this_path\$reg_list_file"|select -Unique|?{$_.trim() -ne ""})){
    Traverse-RegistryKey $key #$temp_csv_file
}
$Script:ie_settings|out-file -FilePath "$this_path\$this_machine-ie.csv" -Encoding utf8 -Force
# Try{
	# If( !(test-path $remote_folder -ErrorAction Stop) ){
	    # new-item -ItemType Directory -path $remote_folder -Force 1>$null
	# }
	# del "$remote_folder$this_machine-ie.csv" -force -ErrorAction Stop
	# copy "$this_path\$this_machine-ie.csv" $remote_folder -force -ErrorAction Stop
	# "get_registry_value.ps1","ie_regkey_list.txt","$this_machine-ie.csv"|%{del "$this_path\$_" -force -ErrorAction Ignore}
# }Catch{
# }Finally{}
